# from copy import deepcopy
# from app.finance.account.model import Account as AccountTable
# from app.finance.account import dao
# from common.mixins import DictMixin
# from common.utils.utils import custom_marshal_pagination
# from common.utils.pinyin import get_first_letter_pinyin
# from exts import db
#
#
# # ------------- route ------------
# def create(user_id, **kwargs):
#     if not kwargs.get('short_name'):
#         kwargs['short_name'] = get_first_letter_pinyin(kwargs.get("name"))
#     new_obj = DictMixin.from_dict(AccountTable, kwargs)
#     new_obj.creator_id = user_id
#     db.session.add(new_obj)
#     db.session.commit()
#     return new_obj
#
#
# def get_by_page(user_id, **kwargs):
#     pagination = dao.get_by_page(**kwargs)
#     pagination = custom_marshal_pagination(pagination)
#     return pagination
#
#
# def get(user_id, obj_id):
#     return AccountTable.query.filter_by(id=obj_id).first()
#
#
# def update(user_id, obj_id, **kwargs):
#     obj = AccountTable.query.filter_by(id=obj_id).first()
#     new_obj = DictMixin.from_dict(deepcopy(obj), kwargs)
#     new_obj.updater_id = user_id
#     # 当名称发生修改时，自动更新short_name
#     if obj.name != new_obj.name:
#         new_obj.short_name = get_first_letter_pinyin(new_obj.name)
#     db.session.commit()
#     return new_obj
#
#
# def delete(user_id, obj_id):
#     obj = AccountTable.query.filter_by(id=obj_id).first()
#     db.session.delete(obj)
#     db.session.commit()
#     return obj.id
